package com.example.yy.zyfypt_223yy.model;

import com.example.yy.zyfypt_223yy.iface.LogoutListener;
import com.example.yy.zyfypt_223yy.iface.Logoutiface;
import com.example.yy.zyfypt_223yy.service.LogoutService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by BYS on 2017/5/23.
 */

public class LogoutModel implements Logoutiface {
    private Retrofit retrofit;
    private String BASEURL = "http://amicool.neusoft.edu.cn/";

    public LogoutModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void getResultList(String sessionID, final LogoutListener listener) {
        LogoutService logoutService=retrofit.create(LogoutService.class);
        Call<String> call=logoutService.logout(sessionID);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                listener.onResponse(response.body());
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
